
//
//  ICBaseViewController.m
//  ICome
//
//  Created by zhang_rongwu on 16/3/3.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICBaseViewController.h"
#import "ICHeaderFile.h"
#import "UIBarButtonItem+SXCreate.h"

@interface ICBaseViewController()

@end
@implementation ICBaseViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;

//    self.view.backgroundColor = BACKGROUNDCOLOR;
//
//    if (self.navigationController.childViewControllers.count > 1) {
//        //[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"App_back_blue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)]];
//
//        self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImageName:@"App_back_white" itemType:UIBarButtonItemTypeLeft target:self action:@selector(backClick)];
//
//        self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
//    }
//    [self setNavBackgroundColor:NE_BACKGROUND_COLOR];
//    [self setNavShadowColor:NE_BACKGROUND_COLOR];
//    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.view.backgroundColor = BACKGROUNDCOLOR;

    if (self.navigationController.childViewControllers.count > 1) {
        //[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"App_back_blue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)]];
        
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImageName:@"App_back_white" itemType:UIBarButtonItemTypeLeft target:self action:@selector(backClick)];

        self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    }
    [self setNavBackgroundColor:NE_BACKGROUND_COLOR];
    [self setNavShadowColor:NE_BACKGROUND_COLOR];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
}

//- (void)setTitle:(NSString *)title
//{
//    //dispatch_async(dispatch_get_main_queue(), ^{
//        [super setTitle:title];
//        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth-200)/2., 0, 200, 44)];
//        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
//        titleLabel.textColor = [UIColor whiteColor];
//        titleLabel.textAlignment = NSTextAlignmentCenter;
//        titleLabel.text = title;
//        self.navigationItem.titleView = titleLabel;
//    //});
//}

- (void)setNavBackgroundColor:(UIColor *)navBackgroundColor {
    UINavigationBar * navBar = self.navigationController.navigationBar;
    [navBar setBackgroundImage:[UIImage imageWithColor:navBackgroundColor size:CGSizeMake(App_Frame_Width, 1)] forBarMetrics:UIBarMetricsDefault];
    [navBar setBarTintColor:navBackgroundColor];
}


- (void)setNavShadowColor:(UIColor *)navShadowColor {
    UINavigationBar * navBar = self.navigationController.navigationBar;
    [navBar setShadowImage:[UIImage imageWithColor:navShadowColor size:CGSizeMake(App_Frame_Width, 0.5)]];
}


- (void)backClick {
    if ((self.presentedViewController || self.presentingViewController) && self.childViewControllers.count == 1) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }else
        [self.navigationController popViewControllerAnimated:YES];
}


- (BOOL)push:(NSDictionary *)param {
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [ICTools appClearDisk];
}


//- (UIStatusBarStyle)preferredStatusBarStyle
//{
//    return UIStatusBarStyleLightContent;//UIStatusBarStyleDefault;
//}


- (id)initWithRouterParams:(NSDictionary *)params {
    self = [super init];
    if (self) {
        _parameterDictionary=params;
        _tabBarIndex = [params[@"tabBarIndex"] intValue];
    }
    return self;
}


@end
